package logic

import (
	"context"
	"goods-mgr/model"

	"goods-mgr/orderrpc/internal/svc"
	"goods-mgr/orderrpc/orderrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type ListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ListLogic {
	return &ListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *ListLogic) List(in *orderrpc.ListRequest) (*orderrpc.ListResponse, error) {
	// todo: add your logic here and delete this line

	var carts []model.Cart
	model.DB.Debug().Find(&carts)
	var cartList []*orderrpc.CartList

	for _, cart := range carts {

		list := orderrpc.CartList{
			OrderId:  cart.OrderId,
			Quantity: cart.Quantity,
			Selected: cart.Selected,
		}
		cartList = append(cartList, &list)
	}
	return &orderrpc.ListResponse{
		List: cartList,
	}, nil
}
